package com.itrip.itripauth.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itrip.itripauth.entity.AreaDic;
import com.itrip.itripauth.entity.Hotel;
import com.itrip.itripauth.entity.LabelDic;
import com.itrip.itripauth.service.AreaDicService;
import com.itrip.itripauth.service.HotelFeatureService;
import com.itrip.itripauth.service.HotelService;
import com.itrip.itripauth.service.HotelTradingAreaService;
import com.itrip.itripauth.util.Dto;
import com.itrip.itripauth.util.DtoUtil;
import com.itrip.itripauth.vo.EmptyUtils;
import com.itrip.itripauth.vo.HotelVideoDescVO;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 酒店表 前端控制器
 * </p>
 *
 * @author 四阶段项目二组
 * @since 2020-02-25
 */
@RestController
@RequestMapping("/biz/api/hotel")
@CrossOrigin
public class HotelController {

    @Autowired
    private HotelService hotelService;
    @Autowired
    private HotelFeatureService hotelFeatureService;

    @Autowired
    private AreaDicService areaDicService;
    @Autowired
    private HotelTradingAreaService hotelTradingAreaService;
    @GetMapping("/getimg/{hotelId}")
    public Dto getImg(@PathVariable Integer hotelId){

        return DtoUtil.returnDataSuccess(hotelService.getImg(hotelId));
    }
    @ApiOperation("酒店详情查询")
    @GetMapping("queryhoteldetails/{hotelId}")
    public Dto queryhoteldetails(
            @ApiParam(name = "hotelId",required = true)
            @PathVariable String hotelId
    ){
        List<LabelDic> hotelList= hotelService.hotelList(Integer.valueOf(hotelId));
        LabelDic labelDic=new LabelDic();
        Hotel hotel = hotelService.getById(Integer.valueOf(hotelId));
        labelDic.setName("酒店介绍");
        labelDic.setDescription(hotel.getDetails());
        hotelList.add(1,labelDic);
        return  DtoUtil.returnDataSuccess(hotelList);
    }
    @ApiOperation("查询酒店设施")
    @GetMapping("queryhotelfacilities/{hotelId}")
    public Dto queryhotelfacilities(
            @ApiParam(name = "hotelId",required = true)
            @PathVariable String hotelId){
        Hotel hotel = hotelService.getById(Integer.valueOf(hotelId));
        return  DtoUtil.returnDataSuccess(hotel.getFacilities());
    }
    @ApiOperation("查询酒店政策")
    @GetMapping("queryhotelpolicy/{hotelId}")
    public Dto queryhotelpolicy(
            @ApiParam(name = "hotelId",required = true)
            @PathVariable String hotelId){
        Hotel hotel = hotelService.getById(Integer.valueOf(hotelId));
        return  DtoUtil.returnDataSuccess(hotel.getHotelPolicy());
    }
    @ApiOperation("查询酒店名称，商圈，特色")
    @GetMapping("getvideodesc/{hotelId}")
    public Dto getvideodesc(
            @ApiParam(name = "hotelId",required = true)
            @PathVariable String hotelId){
        //根据酒店id查询出商圈的名称
        List<AreaDic> areaDicList = hotelTradingAreaService.areaDicList(Integer.valueOf(hotelId));
        //创建HotelVideoDescVO对象
        HotelVideoDescVO hotelVideoDescVO=new HotelVideoDescVO();

        //将查询出商圈的名称循环遍历赋给一个List<String集合>
        List<String> tradingAreaNameList=new ArrayList<>();
        for (AreaDic areaDic:areaDicList) {
            tradingAreaNameList.add(areaDic.getName());
        }
        hotelVideoDescVO.setTradingAreaNameList(tradingAreaNameList);
        //将查询出来的酒店特色循环遍历赋给一个List<String集合>
        List<String> hotelFeatureList=new ArrayList<>();
        //根据酒店id查询出酒店特色
        List<LabelDic> labelDicList = hotelFeatureService.labelList(Integer.valueOf(hotelId));
        for (LabelDic labelDic:labelDicList) {
            hotelFeatureList.add(labelDic.getName());
        }
        hotelVideoDescVO.setHotelFeatureList(hotelFeatureList);
        hotelVideoDescVO.setHotelName(hotelService.getById(Integer.valueOf(hotelId)).getHotelName());
        return  DtoUtil.returnDataSuccess(hotelVideoDescVO);
    }
    @ApiOperation("查询商圈")
    @GetMapping("/querytradearea/{cityId}")
    public Dto querytradearea(
            @ApiParam(value = "cityId",required = true)
            @PathVariable Long cityId){
        List<AreaDic> areaDicList = null;
        if (EmptyUtils.isNotEmpty(cityId)) {

            areaDicList = areaDicService.selectAreaDicBycityIdValue(1, Math.toIntExact(cityId));

        }else {
            DtoUtil.returnFail("cityId不能为空");
        }

        return DtoUtil.returnDataSuccess(areaDicList);
    }

}
